package com.five.admin.server.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.five.admin.dto.RoleUpdateMenuDto;
import com.five.admin.mapper.RoleMapper;
import com.five.admin.server.RoleService;
import com.five.pojo.entity.Role;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {
    @Override
    public void deleteRole(Long adminId) {
        getBaseMapper().deleteRoleByAdminId(adminId);
    }

    @Override
    public List<Long> findByAdminId(Long adminId) {
        return getBaseMapper().findByAdminId(adminId);
    }

    @Override
    public int updateRoleAndMenu(RoleUpdateMenuDto roleUpdateMenuDto) {
        getBaseMapper().deleteRoleAndMenu(roleUpdateMenuDto.getId());
        if (roleUpdateMenuDto.getMenuIds().isEmpty()){
            return 1;
        }

        return getBaseMapper().insertRoleAndMenu(roleUpdateMenuDto.getId(),roleUpdateMenuDto.getMenuIds());
    }

    @Override
    public int deleteRoleMenu(Long roleId) {
        getBaseMapper().deleteRoleAndMenu(roleId);
        return 1;
    }
}
